package com.service;


import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;


@Service
public class ServiceA {

    @Autowired
    private RestTemplate restTemplate;


    @HystrixCommand(fallbackMethod = "callback")
    public String add(int x, int y)
    {
       // String str = "http://127.0.0.1:2222/add?x=%d&y=%d";
       // String url = String.format(str,x,y);
        String str = "http://service-b/add?x=%d&y=%d";
        String url = String.format(str,x,y);
        String sum = restTemplate.getForObject(url,String.class);
        return sum;
    }

    public String callback(int x,int y)
    {
        System.out.println("熔断，看一下来了没");
        return "熔断，看一下来了没";
    }
}
